package org.fin.pojo;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

public class Configuration {

  /** 数据源对象，用于获取数据库连接 */
  private DataSource dataSource;

  /**
   * k: sql执行配置的唯一标识：mapper的namespace + . + sql配置的id
   * v: MappedStatement对象：包含对应sql的具体配置信息
   */
  private Map<String, MappedStatement> sqlStatements = new HashMap<>();


  /**
   * 存入一条MappedStatement
   *
   * @param id          存入一条MappedStatement的唯一标识: namespace.id
   * @param statement   对应的MappedStatement
   */
  public void putMappedStatement(String id, MappedStatement statement) {
    sqlStatements.put(id, statement);
  }


  /**
   * 以Map的形式存入多条MappedStatement
   *
   * @param statements  要存入的多条MappedStatement，kv解释查看
   */
  public void putMappedStatements(Map<String, MappedStatement> statements) {
    sqlStatements.putAll(statements);
  }

  public MappedStatement getStatement(String id) {
    return sqlStatements.get(id);
  }


  public Map<String, MappedStatement> getSqlStatements() {
    return sqlStatements;
  }

  public void setSqlStatements(Map<String, MappedStatement> sqlStatements) {
    this.sqlStatements = sqlStatements;
  }

  public DataSource getDataSource() {
    return dataSource;
  }

  public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
  }

}
